package com.jan.l4;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

public class MouseKeyComposite
    extends Composite
{

  Label output;

  public MouseKeyComposite(Composite parent)
  {
    super(parent, SWT.NONE);
    Button typed = new Button(this, SWT.PUSH);
    typed.setText("Typed");
    typed.setLocation(2, 10);
    typed.pack();
    typed.addKeyListener(new KeyAdapter()
    {
      public void keyPressed(KeyEvent e)
      {
        keyHandler();
      }
    });
    Listener UntypedListener = new Listener()
    {
      public void handleEvent(Event event)
      {
        switch (event.type)
        {
          case SWT.MouseEnter:
            output.setText("Mouse Enter");
            break;
          case SWT.MouseExit:
            output.setText("Mouse Exit");
            break;
        }
      }
    };
    Button untyped = new Button(this, SWT.PUSH);
    untyped.setText("Untyped");
    untyped.setLocation(80, 10);
    untyped.pack();
    untyped.addListener(SWT.MouseExit, UntypedListener);
    output = new Label(this, SWT.SHADOW_OUT);
    output.setBounds(40, 70, 90, 40);
    output.setText("No Event");
    pack();

  }

  void keyHandler()
  {
    output.setText("Key Event");
  }
}
